package command;

import java.util.HashMap;
import java.util.Map;

import commandimpl.AlterCommand;
import commandimpl.DeleteCommand;
import commandimpl.ExitCommand;
import commandimpl.HelpCommand;
import commandimpl.SelectCommand;
import commandimpl.SetupCommand;

public  class CommandFactory {
	public static enum CommandCode {
		HELP, EXIT, SETUP, DELETE, ALTER, SELECT
	}

	private static Map<CommandCode, Class<? extends Command>> cmdmap = new HashMap<>();

	static {
		cmdmap.put(CommandCode.HELP, HelpCommand.class);
		cmdmap.put(CommandCode.EXIT, ExitCommand.class);
		cmdmap.put(CommandCode.SETUP, SetupCommand.class);
		cmdmap.put(CommandCode.DELETE, DeleteCommand.class);
		cmdmap.put(CommandCode.ALTER, AlterCommand.class);
		cmdmap.put(CommandCode.SELECT, SelectCommand.class);
	}

	public static Command buildCommand(CommandCode cmd){
		Class<?extends Command>cmdclass = cmdmap.get(cmd);
		if(cmdclass!=null){
			try {
				return cmdclass.newInstance();
			} catch (InstantiationException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			} catch (IllegalAccessException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		return null;
	};
}
